<?php

/*
 * Page Name: Essential Class
 * Author: Avik Kundu
 * Created On : 28th JULY,2011
 * Modified On :
 * 
 */

class clsEssential
{	
	
	public static function getPageLink($serverType)
	{
		$arrPageLink = array();
		$fullPageLink = $_SERVER['REQUEST_URI'];	
		if($serverType=="testing")
		{
			$arrPageLink = explode("/newsite/",$fullPageLink);
			$finalLink = $arrPageLink[1];
		}
		else
		{
			$finalLink = $fullPageLink;
		}
		return $finalLink;
	}
	
	public static function setPageContent()
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		
		$conditionArr = array();
		$pagelink = clsEssential::getPageLink('testing');
		$conditionArr['page_link'] = $pagelink;
		$sql = "SELECT page_content FROM tbl_page_content WHERE page_link_id =(SELECT id FROM tbl_pagename_link WHERE page_link='".$conditionArr['page_link']."')";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$dataToShow = htmlspecialchars_decode(stripslashes($data['page_content']));
		}
		return $dataToShow;
	}
	
	function LoginProcess($username,$password)
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		
		$sql = "SELECT COUNT(*) as cntAdmin FROM tbl_users WHERE user_name='".$username."' AND password='".$password."' AND is_active='Y' AND is_admin='Y'";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$cntAdmin = $data['cntAdmin'];
		}
		return $cntAdmin;
	}
	
	function LoginProcessDomain($username,$password,$ddlDomain)
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$sql = "SELECT COUNT(*) as cntAdmin FROM tbl_admin_users WHERE user_name='".$username."' AND password='".$password."' AND domain='".$ddlDomain."' AND is_active='Y' ";
		//print $sql;exit;
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$cntAdmin = $data['cntAdmin'];
		}
		return $cntAdmin;
	}
	
	function SavingPage($pageName,$desc,$userid)
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$pageName = addslashes($pageName);
		$pageName = str_replace(" ","-",$pageName);
		$pageLink = "".$pageName;
		
		//Create a page in the folder
		$BASE_PATH="";
		$fileName = $BASE_PATH.$pageName.".php";
		$fh = fopen($fileName, "w+");
		if($fh==false)
		{
			die("unable to create file");
		}
		else
		{
			$sql = "INSERT INTO tbl_pagename_link(page_name,page_link,created_on,is_active,modified_by) VALUES ('".$pageName."','".$pageLink."','','Y',$userid)";
			$run = mysql_query($sql);
			$sqlC = "SELECT max(id) as maxid FROM tbl_pagename_link WHERE modified_by=$userid AND is_active='Y'";
			$runC = mysql_query($sqlC);
			while ($dataC = mysql_fetch_array($runC))
			{
				$maxid = $dataC['maxid'];
			}
			
			$sqlM = "INSERT INTO tbl_page_content(page_link_id,page_content,is_active,modified_by) VALUES ($maxid,'$desc','Y',$userid)";
			$runM = mysql_query($sqlM);
		}
		if($runM)
			return "1";
		
	}
	
	function IsPageExists($pagename)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$pageName = addslashes($pagename);
		$pageName = str_replace(" ","-",$pagename);
		$sql = "SELECT COUNT(*) AS PAGECOUNT FROM `tbl_pagename_link` WHERE `page_name` = '$pagename' AND is_active='Y'";
		$runC = mysql_query($sql);
		while ($data = mysql_fetch_array($runC))
		{
			$pagecount = $data['PAGECOUNT'];
		}
		if($pagecount>=1)
		{
			return "1";
		}
		
	}
	
	function quickLinks()
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrQuickLinks = array();
		$sql = "SELECT id,page_name,page_link FROM `tbl_pagename_link` WHERE is_active='Y'";
		$runC = mysql_query($sql);
		$count =0;
		while ($data = mysql_fetch_array($runC))
		{
			$arrQuickLinks[$count]['id'] = $data['id'];
			$arrQuickLinks[$count]['page_name'] = $data['page_name'];
			//$arrPageLink = explode("",$data['page_link']);
			$arrQuickLinks[$count]['page_link'] = $data['page_link'];
			$count++;
		}
		return $arrQuickLinks;
	}
	
	public static function SavingUploadingImages($vincode,$orgimagepath)
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		
		//$sql = "INSERT INTO tbl_vehicle_details(Bannister_unique_vehicle_no,OrgImagePath,ThumbImagePath,modified_by) VALUES ('".$vincode."','".$orgimagepath."','".$thumbimagepath."',$userid)";
		
		$sql = "INSERT INTO tbl_car_images (unique_no,image_path,is_active) VALUES ('".$vincode."','".$orgimagepath."','Y')";
		
		//print $sql;
		
		file_put_contents("C:\\sql.txt",$sql);
		$run = mysql_query($sql);
			
		if($run)
			return "1";
		
	}
	
	public static function distinctBanisterVinCodes()
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVinCode = array();
		$sql = "SELECT distinct(Bannister_unique_vehicle_no) FROM tbl_vehicle_details t";
		$runC = mysql_query($sql);
		$count =0;
		while ($data = mysql_fetch_array($runC))
		{
			$arrVinCode[$count]['vincode'] = $data['Bannister_unique_vehicle_no'];

			$count++;
		}
		return $arrVinCode;
	}
	
	public static function UploadFilesForEachVinCode($vincode)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrUploadFiles = array();
		$sql = "SELECT * FROM tbl_vehicle_details WHERE Bannister_unique_vehicle_no='$vincode'";
		$runC = mysql_query($sql);
		$count =0;
		while ($data = mysql_fetch_array($runC))
		{
			$arrUploadFiles[$count]['id'] = $data['VehicleSeq'];
			$arrUploadFiles[$count]['oPath'] = $data['OrgImagePath'];
			$arrUploadFiles[$count]['tPath'] = $data['ThumbImagePath'];

			$count++;
		}
		return $arrUploadFiles;
	}
	
	public static function DeleteImages($id)
	{
		
		$objdb = new bannisterDB();
		$objdb->connectdb();
		
		$sql = "DELETE FROM tbl_vehicle_details WHERE VehicleSeq=$id";
		$run = mysql_query($sql);
			
		if($run)
			return "1";
		
	}
	
	public static function SelectRecordsDetails($id)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrUploadFiles = array();
		$sql = "SELECT * FROM tbl_vehicle_details WHERE VehicleSeq=$id";
		$runC = mysql_query($sql);
		$count =0;
		while ($data = mysql_fetch_array($runC))
		{
			$arrUploadFiles['oPath'] = $data['OrgImagePath'];
			$arrUploadFiles['tPath'] = $data['ThumbImagePath'];

		}
		return $arrUploadFiles;
	}
	
	public static function getPageContent($pageId)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$conditionArr = array();
		$pageId = $pageId;
		$sql = "SELECT page_content FROM tbl_page_content WHERE page_link_id =".$pageId;
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$dataToShow = stripslashes($data['page_content']);
		}
		return $dataToShow;
	}
	
	public function getBasicData($vid)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,year,make,model,stocknumber,style,exteriorcolor,passengers,Kilometers,doors,fuel,engine,car_status,interior,is_sold 
		FROM tbl_car_basic WHERE is_active='Y' ";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		$count=0;
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["year"]= $data['year'];
			$vehicleArr[$count]["make"]= $data['make'];
			$vehicleArr[$count]["model"]= $data['model'];
			$vehicleArr[$count]["stocknumber"]= $data['stocknumber'];
			$vehicleArr[$count]["style"]= $data['style'];
			$vehicleArr[$count]["exteriorcolor"]= $data['exteriorcolor'];
			$vehicleArr[$count]["passengers"]= $data['passengers'];
			$vehicleArr[$count]["Kilometers"]= $data['Kilometers'];
			$vehicleArr[$count]["doors"]= $data['doors'];
			$vehicleArr[$count]["fuel"]= $data['fuel'];
			$vehicleArr[$count]["engine"]= $data['engine'];
			$vehicleArr[$count]["car_status"]= $data['car_status'];
			$vehicleArr[$count]["interior"]= $data['interior'];
			$vehicleArr[$count]["is_sold"]= $data['is_sold'];
			//$arrVehiclesHistory[$count]['is_sold']=$data['is_sold'];
			$count++;
		}
		return $vehicleArr;
	}
		
	public function getCarBrakesData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,ABS,Electronic_brakeforce_distribution,Front_brakes,Rear brakes,is_active 
				FROM `tbl_car_brakes` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$sql .=" order by year DESC "; 
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["ABS"]= $data['ABS'];
			$vehicleArr[$count]["Electronic_brakeforce_distribution"]= $data['Electronic_brakeforce_distribution'];
			$vehicleArr[$count]["Front_brakes"]= $data['Front_brakes'];
			$vehicleArr[$count]["Rear_brakes"]= $data['Rear_brakes'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getChildSafetyData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,Child_safety_locks,Child_seat_anchors,is_active
				FROM `tbl_car_child_safety` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Child_safety_locks"]= $data['Child_safety_locks'];
			$vehicleArr[$count]["Child_seat_anchors"]= $data['Child_seat_anchors'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarConvenienceFeaturesData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,Adjustable_pedals,Center_console,Cruise_control,Cupholders,Front_power_outlet,Multi-function_remote,Overhead_console,Power_steering,Storage,is_active
				FROM `tbl_car_convenience_features` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Adjustable_pedals"]= $data['Adjustable_pedals'];
			$vehicleArr[$count]["Center_console"]= $data['Center_console'];
			$vehicleArr[$count]["Cruise_control"]= $data['Cruise_control'];
			$vehicleArr[$count]["Cupholders"]= $data['Cupholders'];
			$vehicleArr[$count]["Front_power_outlet"]= $data['Front_power_outlet'];
			$vehicleArr[$count]["Multi-function_remote"]= $data['Multi-function_remote'];
			$vehicleArr[$count]["Overhead_console"]= $data['Overhead_console'];
			$vehicleArr[$count]["Multi-function_remote"]= $data['Multi-function_remote'];
			$vehicleArr[$count]["Power_steering"]= $data['Power_steering'];
			$vehicleArr[$count]["Storage"]= $data['Storage'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarDoorsData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,Liftgate_window,Rear_door_type,is_active
				FROM `tbl_car_doors` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Liftgate_window"]= $data['Liftgate_window'];
			$vehicleArr[$count]["Rear_door_type"]= $data['Rear_door_type'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarDriverSeatData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,Adjustable_lumbar_support,Heated,Height_adjustable,Power_adjustments,is_active
				FROM `tbl_car_driver_seat` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Adjustable_lumbar_support"]= $data['Adjustable_lumbar_support'];
			$vehicleArr[$count]["Heated"]= $data['Heated'];
			
			$vehicleArr[$count]["Height_adjustable"]= $data['Height_adjustable'];
			$vehicleArr[$count]["Power_adjustments"]= $data['Power_adjustments'];
			
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
		
	public function getAllVIN()
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleVin = array();
		$sql = "SELECT distinct(unique_id) FROM tbl_car_basic";
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleVin[$count]= $data['unique_id'];
			$count++;
		}
		return $vehicleVin;
	}
	
	public function getCarExtendedData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,
		max_seating,std_seating,truck_bed_length,rear_tire_type,rear_wheel_dia,tire_type,wheel_dia,
		tank_1_capacity,tank_2_capacity,engine,transmissions,gears,is_active
		FROM `tbl_car_extended` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["max_seating"]= $data['max_seating'];
			$vehicleArr[$count]["std_seating"]= $data['std_seating'];
			$vehicleArr[$count]["truck_bed_length"]= $data['truck_bed_length'];
			$vehicleArr[$count]["rear_tire_type"]= $data['rear_tire_type'];
			$vehicleArr[$count]["rear_wheel_dia"]= $data['rear_wheel_dia'];
			$vehicleArr[$count]["tire_type"]= $data['tire_type'];
			
			$vehicleArr[$count]["wheel_dia"]= $data['wheel_dia'];
			$vehicleArr[$count]["tank_1_capacity"]= $data['tank_1_capacity'];
			$vehicleArr[$count]["tank_2_capacity"]= $data['tank_2_capacity'];
			$vehicleArr[$count]["engine"]= $data['engine'];
			$vehicleArr[$count]["transmissions"]= $data['transmissions'];
			$vehicleArr[$count]["gears"]= $data['gears'];
			
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
		
	public function getCarExteriorFeaturesData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,
		Adjustable_rear_headrests,Front_headrests,In_Car_Entertainment,Clock,Compass,External_temperature_display,
		Low_fuel_level,Tachometer,Trip_computer,Exterior_entry_lights,Front_fog_lights,is_active
		FROM `tbl_car_exterior_features` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Adjustable_rear_headrests"]= $data['Adjustable_rear_headrests'];
			$vehicleArr[$count]["Front_headrests"]= $data['Front_headrests'];
			$vehicleArr[$count]["In_Car_Entertainment"]= $data['In_Car_Entertainment'];
			$vehicleArr[$count]["Clock"]= $data['Clock'];
			$vehicleArr[$count]["Compass"]= $data['Compass'];
			$vehicleArr[$count]["External_temperature_display"]= $data['External_temperature_display'];
			
			$vehicleArr[$count]["Low_fuel_level"]= $data['Low_fuel_level'];
			$vehicleArr[$count]["Tachometer"]= $data['Tachometer'];
			$vehicleArr[$count]["Trip_computer"]= $data['Trip_computer'];
			$vehicleArr[$count]["Exterior_entry_lights"]= $data['Exterior_entry_lights'];
			$vehicleArr[$count]["Front_fog_lights"]= $data['Front_fog_lights'];
			
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			
			$vehicleArr[$count]["other_info"] = $data['other_info'];
			
			$count++;
		}
		return $vehicleArr;
	}
		
	public function getCarFeaturesData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,other_options_features FROM `tbl_car_features`";
		if(strlen($vid)>0)
		{
			$sql .=" WHERE unique_id='".$vid."'";
		}
		
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["other_options_features"]= htmlspecialchars_decode(stripslashes(($data['other_options_features'])));
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarOptionsData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,option_info FROM `tbl_options_data`";
		if(strlen($vid)>0)
		{
			$sql .=" WHERE unique_id='".$vid."'";
		}
			
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["option_info"]= htmlspecialchars_decode(stripslashes(($data['option_info'])));
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarPriceData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,
		original_price,offered_price,featured_price,is_featured,discount,is_active
		FROM `tbl_car_price` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["original_price"]= $data['original_price'];
			$vehicleArr[$count]["offered_price"]= $data['offered_price'];
			$vehicleArr[$count]["featured_price"]= $data['featured_price'];
			$vehicleArr[$count]["is_featured"]= $data['is_featured'];
			$vehicleArr[$count]["discount"]= $data['discount'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarSeatsData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,
		Climate_controlled,Front_seat_type,Passenger_Seating,Upholstery,is_active
		FROM `tbl_car_seats` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Climate_controlled"]= $data['Climate_controlled'];
			$vehicleArr[$count]["Front_seat_type"]= $data['Front_seat_type'];
			$vehicleArr[$count]["Passenger_Seating"]= $data['Passenger_Seating'];
			$vehicleArr[$count]["Upholstery"]= $data['Upholstery'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarSecurityData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,
		Anti-theft_alarm_system,Engine_immobilizer,is_active FROM `tbl_car_security` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Anti-theft_alarm_system"]= $data['Anti-theft_alarm_system'];
			$vehicleArr[$count]["Engine_immobilizer"]= $data['Engine_immobilizer'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}

	public function getCarWarrantyData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,miles,
		type,months,is_active FROM `tbl_car_warranty` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["miles"]= $data['miles'];
			$vehicleArr[$count]["type"]= $data['type'];
			$vehicleArr[$count]["months"]= $data['months'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}

	public function getCarWeightMeasurementData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,gross_vehicle_weight_range,base_towing_capacity,
		max_payload,max_towing_capacity,is_active FROM `tbl_car_weight_measurement` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["gross_vehicle_weight_range"]= $data['gross_vehicle_weight_range'];
			$vehicleArr[$count]["base_towing_capacity"]= $data['base_towing_capacity'];
			$vehicleArr[$count]["max_payload"]= $data['max_payload'];
			$vehicleArr[$count]["max_towing_capacity"]= $data['max_towing_capacity'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarWindowData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,Front_wipers,Power_windows,
		Privacy_glass,Rear_defogger,Rear_wiper,is_active FROM `tbl_car_windows` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Front_wipers"]= $data['Front_wipers'];
			$vehicleArr[$count]["Power_windows"]= $data['Power_windows'];
			$vehicleArr[$count]["Privacy_glass"]= $data['Privacy_glass'];
			$vehicleArr[$count]["Rear_defogger"]= $data['Rear_defogger'];
			$vehicleArr[$count]["Rear_wiper"]= $data['Rear_wiper'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarComfortFeaturesData($vid)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT id,unique_id,Cargo_area_light,Dash_trim,Steering_wheel_trim,
		Floor_Mat_Material,Floor_Mats,Reading_lights,is_active FROM `tbl_comfort_features` WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_id='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["Cargo_area_light"]= $data['Cargo_area_light'];
			$vehicleArr[$count]["Dash_trim"]= $data['Dash_trim'];
			$vehicleArr[$count]["Steering_wheel_trim"]= $data['Steering_wheel_trim'];
			$vehicleArr[$count]["Floor_Mat_Material"]= $data['Floor_Mat_Material'];
			$vehicleArr[$count]["Floor_Mats"]= $data['Floor_Mats'];
			$vehicleArr[$count]["Reading_lights"]= $data['Reading_lights'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}	

	public function insertUniqueDataToEachTable($vid)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$sqlArray = array();
		$count=0;
		$tableNames = array("tbl_car_basic","tbl_car_brakes","tbl_car_child_safety","tbl_car_convenience_features","tbl_car_doors","tbl_car_driver_seat","tbl_car_extended","tbl_car_exterior_features","tbl_car_features","tbl_car_price","tbl_car_seats","tbl_car_security","tbl_car_warranty","tbl_car_weight_measurement","tbl_car_windows","tbl_comfort_features");
		foreach($tableNames as $key=>$tableName)
		{
			$sqlArray[$count] = "INSERT INTO `$tableName` (unique_id,is_active) VALUES ('".$vid."','N')";
			$count++;
		}
		if(count($sqlArray)>0)
		{
			foreach($sqlArray as $sql)
			{
				mysql_query($sql);
			}
		}
	}
	
	public function validate_vin($vin) 
	{
	    $vin = strtolower($vin);
	    if (!preg_match('/^[^\Wioq]{17}$/', $vin)) 
	    { 
	        return false; 
	    }
	    $weights = array(8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2);
		$transliterations = array(
        "a" => 1, "b" => 2, "c" => 3, "d" => 4,
        "e" => 5, "f" => 6, "g" => 7, "h" => 8,
        "j" => 1, "k" => 2, "l" => 3, "m" => 4,
        "n" => 5, "p" => 7, "r" => 9, "s" => 2,
        "t" => 3, "u" => 4, "v" => 5, "w" => 6,
        "x" => 7, "y" => 8, "z" => 9
	    );
	    $sum = 0;
	    for($i = 0 ; $i < strlen($vin) ; $i++ ) 
	    { 
	        if(!is_numeric($vin{$i})) {
	            $sum += $transliterations[$vin{$i}] * $weights[$i];
	        } else {
	            $sum += $vin{$i} * $weights[$i];
	        }
	    }
	    $checkdigit = $sum % 11;
	    if($checkdigit == 10) 
	    {
	        $checkdigit = "x";
	    }
	    return ($checkdigit == $vin{8});
	}
	
	public function getVehiclesPageData($status,$domain)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		if($domain==0)
		{
			$sql = "SELECT a.sold_on, a.is_sold, a.style,a.stocknumber,a.id,a.unique_id,a.year,a.make,a.model,b.original_price,b.offered_price,b.featured_price
			FROM `tbl_car_basic` a , `tbl_car_price` b WHERE a.is_active='Y' AND a.unique_id=b.unique_id ";
			if(strlen($status)>0)
			{
				$sql.=" AND a.car_status='$status'";
			}
			$sql.=" order by year DESC ";
		}
		else
		{
			$sql = "SELECT a.sold_on, a.is_sold, a.style,a.stocknumber,a.id,a.unique_id,a.year,a.make,a.model,b.original_price,b.offered_price,b.featured_price
			FROM `tbl_car_basic` a , `tbl_car_price` b, tbl_domain_$domain c WHERE a.is_active='Y' AND a.unique_id=b.unique_id AND c.unique_id=a.unique_id ";
			if(strlen($status)>0)
			{
				$sql.=" AND a.car_status='$status'";
			}
			$sql.=" order by year DESC ";
			
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["year"]= $data['year'];
			$vehicleArr[$count]["make"]= $data['make'];
			$vehicleArr[$count]["model"]= $data['model'];
			$vehicleArr[$count]["original_price"]= $data['original_price'];
			$vehicleArr[$count]["offered_price"]= $data['offered_price'];
			$vehicleArr[$count]["featured_price"]= $data['featured_price'];
			$vehicleArr[$count]["stocknumber"]= $data['stocknumber'];
			$vehicleArr[$count]["style"]= $data['style'];
			$vehicleArr[$count]["is_sold"]= $data['is_sold'];
			$vehicleArr[$count]["sold_on"]= $data['sold_on'];
			
			$count++;
		}
		return $vehicleArr;
	}

	public function getAllMakeData()
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT distinct make FROM tbl_car_basic";
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			if(strlen($data['make'])>0)
			{
				$vehicleArr[$count]["make"]= $data['make'];
			}
			$count++;
		}
		return $vehicleArr;
	}

	public function getAllModelData()
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT distinct model FROM tbl_car_basic";
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			if(strlen($data['model'])>0)
			{
				$vehicleArr[$count]["model"]= $data['model'];
			}
			$count++;
		}
		return $vehicleArr;
	}

	public function getAllYearData()
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT distinct year FROM tbl_car_basic";
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			if(strlen($data['year'])>0)
			{
				$vehicleArr[$count]["year"]= $data['year'];
			}
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getVehiclesPageDataFiltered($type,$make,$model,$year,$km,$price,$domain)
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		if($domain==0)
		{
			$sql = "SELECT a.sold_on, a.is_sold, a.style,a.stocknumber,a.id,a.unique_id,a.year,a.make,a.model,b.original_price,b.offered_price,b.featured_price
			FROM `tbl_car_basic` a , `tbl_car_price` b WHERE a.is_active='Y' AND a.unique_id=b.unique_id order by year DESC  ";
		}
		else
		{
			$sql = "SELECT a.sold_on, a.is_sold, a.style,a.stocknumber,a.id,a.unique_id,a.year,a.make,a.model,b.original_price,b.offered_price,b.featured_price
			FROM `tbl_car_basic` a , `tbl_car_price` b, tbl_domain_$domain c WHERE c.is_active='Y' AND a.unique_id=b.unique_id AND a.unique_id=c.unique_id  ";
		
		}
	
		if(strlen($type)>0 && strtolower($type)!="all")
		{
			$sql.=" AND a.car_status='$type'";
		}
		if(strlen($make)>0 && strtolower($make)!="all")
		{
			$sql.=" AND a.make='$make'";
		}
		if(strlen($model)>0 && strtolower($model)!="all")
		{
			$sql.=" AND a.model='$model'";
		}
		if(strlen($year)>0 && strtolower($year)!="all")
		{
			$sql.=" AND a.year='$year'";
		}
		if(strlen($km)>0 && strtolower($km)!="all")
		{
			$sql.=" AND a.Kilometers='$km'";
		}
		if(strlen($price)>0 && strtolower($price)!="all")
		{
			$sql.=" AND b.offered_price='$price'";
		}
		
		if(strlen($sql)>0)
		{
			$sql .=" order by year DESC ";
		}
		
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["year"]= $data['year'];
			$vehicleArr[$count]["make"]= $data['make'];
			$vehicleArr[$count]["model"]= $data['model'];
			$vehicleArr[$count]["original_price"]= $data['original_price'];
			$vehicleArr[$count]["offered_price"]= $data['offered_price'];
			$vehicleArr[$count]["featured_price"]= $data['featured_price'];
			$vehicleArr[$count]["stocknumber"]= $data['stocknumber'];
			$vehicleArr[$count]["style"]= $data['style'];
			$vehicleArr[$count]["is_sold"]= $data['is_sold'];
			$vehicleArr[$count]["sold_on"]= $data['sold_on'];
			
			$count++;
		}
		return $vehicleArr;
	}
	
	
	public function showFeaturedVehicles()
	{
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT a.id,a.unique_id,a.year,a.make,a.model FROM `tbl_car_basic` a, `tbl_car_featured` b 
		WHERE a.is_active='Y' AND a.unique_id=b.unique_id AND b.is_featured='Y'";
		
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["unique_id"]= $data['unique_id'];
			$vehicleArr[$count]["year"]= $data['year'];
			$vehicleArr[$count]["make"]= $data['make'];
			$vehicleArr[$count]["model"]= $data['model'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getUserData($username)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		$sql = "SELECT * FROM `tbl_admin_users` WHERE user_name='$username' ";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$arrVehiclesHistory['userid']=$data['id'];
			$arrVehiclesHistory['username']=$data['user_name'];
			$arrVehiclesHistory['domain']=$data['domain'];
			$arrVehiclesHistory['is_super_admin']=$data['is_super_admin'];
			$arrVehiclesHistory['is_admin']=$data['is_admin'];
		}
		return $arrVehiclesHistory;	
	}
	
	public function getVehicleImages($vinCode)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVehiclesHistory = array();
		$count=0;
		$sql = "SELECT * FROM `tbl_car_images` WHERE unique_no='$vinCode' AND is_active='Y' order by id ASC limit 1";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$arrVehiclesHistory['image_path']=$data['image_path'];
		}
		return $arrVehiclesHistory;	
	}

	public function getCarImages($vid)
	{ 
		$count=0;
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$vehicleArr = array();
		$sql = "SELECT image_path FROM tbl_car_images WHERE is_active='Y'";
		if(strlen($vid)>0)
		{
			$sql .=" AND unique_no='".$vid."'";
		}
		$run= mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$vehicleArr[$count]["id"]= $data['id'];
			$vehicleArr[$count]["image_path"]= $data['image_path'];
			$vehicleArr[$count]["is_active"]= $data['is_active'];
			$count++;
		}
		return $vehicleArr;
	}
	
	public function getCarLocation($vid)
	{
		$sql1 = "SELECT COUNT(*) AS CNT FROM tbl_domain_1 WHERE unique_id='$vid'";
		$run1 = mysql_query($sql1);
		while($data1 = mysql_fetch_array($run1))
		{
			$carLocation = $data1['CNT'];
		}
		if($carLocation==1)
		{
			$domain=1;
		}
		else
		{
			$sql2 = "SELECT COUNT(*) AS CNT FROM tbl_domain_2 WHERE unique_id='$vid'";
			$run2 = mysql_query($sql2);
			while($data2 = mysql_fetch_array($run2))
			{
				$carLocation = $data2['CNT'];
			}
			if($carLocation==1)
			{
				$domain=2;
			}
			else
			{
				$sql3 = "SELECT COUNT(*) AS CNT FROM tbl_domain_3 WHERE unique_id='$vid'";
				$run3 = mysql_query($sql3);
				while($data3 = mysql_fetch_array($run3))
				{
					$carLocation = $data3['CNT'];
				}
				if($carLocation==1)
				{
					$domain=3;
				}
				else
				{
					$sql4 = "SELECT COUNT(*) AS CNT FROM tbl_domain_4 WHERE unique_id='$vid'";
					$run4 = mysql_query($sql4);
					while($data4 = mysql_fetch_array($run4))
					{
						$carLocation = $data4['CNT'];
					}
					if($carLocation==1)
					{
						$domain=4;
					}
				}
			}
		}
			
		return $domain;
	}
	
	
	public function getVehicleAdditionalInfo($vinCode)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrAdditionalInfo = array();
		$count=0;
		$sql = "SELECT * FROM `tbl_additional_info` WHERE unique_id='$vinCode' ";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$arrAdditionalInfo[$count]['additional_info']=htmlspecialchars_decode(stripslashes($data['additional_info']));
			$count++;
		}
		return $arrAdditionalInfo;	
	}
	
	
	
	
	public function getVehicleVideoLinks($vinCode)
	{
		$objdb = new bannisterDB();
		$objdb->connectdb();
		$arrVideoLinks = array();
		$count=0;
		$sql = "SELECT * FROM `tbl_video_links` WHERE unique_id='$vinCode' ";
		$run = mysql_query($sql);
		while ($data = mysql_fetch_array($run))
		{
			$arrVideoLinks[$count]['video_link']=$data['video_link'];
			$count++;
		}
		return $arrVideoLinks;	
	}

}